package com.example.bbs.service.impl;

import com.example.bbs.entity.SelfcheckingScore;
import com.example.bbs.mapper.SelfcheckingScoreMapper;
import com.example.bbs.service.SelfcheckingScoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jiaziyun
 * @since 2021-04-30
 */
@Service
public class SelfcheckingScoreServiceImpl extends ServiceImpl<SelfcheckingScoreMapper, SelfcheckingScore> implements SelfcheckingScoreService {
    @Autowired
    private SelfcheckingScoreMapper selfcheckingScoreMapper;

    @Override
    public String getSesultByIdScore(HashMap<String,String> paramMap) {
        try {
            int id = Integer.parseInt(paramMap.get("id"));
            int sc = Integer.parseInt(paramMap.get("score"));
            SelfcheckingScore selfcheckingScore = selfcheckingScoreMapper.selectById(id);
            String[] split = selfcheckingScore.getScoreAnswer().split(";");
            for (String s : split) {
                String[] split1 = s.split("&");
                if (sc <= Double.parseDouble(split1[0])) {
                    return split1[1];
                }
            }
            return "系统出错，稍后查询";
        } catch (Exception e) {
            return "系统出错，稍后查询";
        }
    }
}
